package com.zhangpingyang.jwttoken.service.impl;

import com.zhangpingyang.jwttoken.nosql.elasticsearch.model.EsProduct;
import com.zhangpingyang.jwttoken.nosql.elasticsearch.repository.EsProductRepository;
import com.zhangpingyang.jwttoken.service.EsProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

/**
 * @Author: Zhang Pingyang
 * @Date: 2019/11/12 0:31
 */
@Service
public class EsProductServiceImpl implements EsProductService {
    @Autowired
    private EsProductRepository esProductRepository;
    @Override
    public int importAll() {
        EsProduct esProduct = new EsProduct();
        esProduct.setId(1L);
        esProduct.setProductSn("呵呵");
        EsProduct save = esProductRepository.save(esProduct);
//        System.out.println(save);
        return 1;
//        Iterable<EsProduct> esProductIterable = productRepository.saveAll(esProductList);
    }
    @Override
    public Iterable<EsProduct> search(String keyword, Integer pageNum, Integer pageSize) {
//        Pageable pageable = PageRequest.of(pageNum, pageSize);
//        esProductRepository.findByNameOrSubTitleOrKeywords(keyword, keyword, keyword, pageable);
        Iterable<EsProduct> all = esProductRepository.findAll();
        return all;
    }
}
